

local M=_G.ClientOHOH.class.new(script, _G.ClientOHOH.files.BaseComponent());
local FriendClass=_G.CommonOHOH.load.FriendCharacter()

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);	

    self.player=self.parent.player
    

    self.FriendFolder= workspace:WaitForChild("Friend".. self.player:GetUserId())

    -- self.FriendFolder=self.parent:WaitForChild_Loop("Friend")
    
    self.FriendList={}
    for _,v in pairs( self.FriendFolder:GetChildren()) do
        self.FriendList[v] =self:CreateObj(v)
    end
   
    self.FriendFolder.ChildAdded:Connect(function(child)
         task.wait()
         self.FriendList[child]=self:CreateObj(child)
    end)

       
    self.FriendFolder.ChildRemoved:Connect(function(child)
        local fc=self.FriendList[child]
        if fc then
            self.FriendList[child]=nil
            fc:dtor()
        end
    end)

end;

function M.dtor(self)
	M.super.dtor(self);
end;


function M.CreateObj(self,character)
    if self.FriendList[character] then
        return
    end
    return FriendClass.new(character,self.player)
end



return M